package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@Tag(name = "分类品牌")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {
    @Autowired
    private ICategoryBrandService categoryBrandService;

    @Operation(summary = "查询分类品牌")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandList();

        return getDataTable(list);
    }

    @Operation(summary = "添加分类品牌")
    @PostMapping
    public AjaxResult add(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.add(categoryBrand);
        return AjaxResult.success();

    }

    @Operation(summary = "删除分类品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult  delete(
            @PathVariable("ids") List<Long> ids) {
        boolean saveOrUpdate = categoryBrandService.removeBatchByIds(ids);
        return toAjax(saveOrUpdate);
    }
    @Operation(summary = "根据分类id查询品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public  AjaxResult selectBrandListByCategoryId(@PathVariable Long categoryId){
     List<Brand>list =categoryBrandService.brandList(categoryId);
     return AjaxResult.success(list);


    }


}


